<?php
	
	// create sidebars
	$sidebars = array('Footer Column 1', 'Footer Column 2', 'Footer Column 3', 'Footer Column 4', 'Footer Column 5', 'Footer Column 6');
	
	// sidebars creating...
	foreach($sidebars as $sidebar) {
		register_sidebar(array('name'=> $sidebar, 'description' => 'Custom Widgets', 'before_widget' => '', 'after_widget' => '', 'before_title' => '<h2', 'after_title' => '</h2>'));
	}
	
	// creating WPress Monster Custom Menu
	add_action('admin_menu', 'wpress_create_menu');

	function wpress_create_menu() {

		add_menu_page('WP Monster Settings', 'WP Settings', 'administrator', "wp", 'wp_settings_html');
		add_submenu_page('wp', 'WP Widgets', 'WP Widgets', 'administrator', 'wp-widget', 'wp_widget_settings_html');
		add_submenu_page('wp', 'WP Contact', 'WP Contact', 'administrator', 'wp-contact', 'wp_contact_html');
		add_action('admin_init', 'register_mysettings');
	
	}
	
	function register_mysettings() {
		register_setting('wpress-settings', 'sitelogo');
		register_setting('wpress-settings', 'copyright_text');
		register_setting('wpress-settings', 'social_icons');
		register_setting('wpress-settings', 'google_analytics_key');
				
		register_setting('wpress-settings', 'ticker_category_id');
		register_setting('wpress-settings', 'ticker_limit');
		register_setting('wpress-settings', 'ticker_title');
		register_setting('wpress-settings', 'disable_newsticker');

		register_setting('wpress-settings', 'short_cut');
		register_setting('wpress-settings', 'news_name');
		register_setting('wpress-settings', 'portfolio_name');
		register_setting('wpress-settings', 'news_limit');
		register_setting('wpress-settings', 'portfolio_limit');
		register_setting('wpress-settings', 'newer_entries');
		register_setting('wpress-settings', 'older_entries');
		register_setting('wpress-settings', 'sub_navigation');
		register_setting('wpress-settings', 'back_name');
		register_setting('wpress-settings', 'search_name');
		register_setting('wpress-settings', 'result_name');
		
		
		register_setting('wpress-widgets', 'footer_column_1');
		register_setting('wpress-widgets', 'footer_column_2');
		register_setting('wpress-widgets', 'footer_column_3');
		register_setting('wpress-widgets', 'footer_column_4');
		register_setting('wpress-widgets', 'footer_column_5');
		register_setting('wpress-widgets', 'footer_column_6');
		
		register_setting('wpress-contact', 'location');
		register_setting('wpress-contact', 'header');
		register_setting('wpress-contact', 'information');
		register_setting('wpress-contact', 'email');
		
		register_setting('wpress-contact', 'form_name');
		register_setting('wpress-contact', 'your_name');
		register_setting('wpress-contact', 'telephone');
		register_setting('wpress-contact', 'email_name');
		register_setting('wpress-contact', 'subject');
		register_setting('wpress-contact', 'message');
		register_setting('wpress-contact', 'submit');
		register_setting('wpress-contact', 'reset');
		register_setting('wpress-contact', 'success');
		register_setting('wpress-contact', 'error');
		
	}
	
	function list_categories($name, $value)
	{
		echo "<select name=$name>";
		echo "<option value=\"\">Select Category</option>";
	
		$categories = get_categories("title_li=&orderby=name");
		foreach ($categories as $category)
		{
			$selected = ($value == $category->term_id) ? "selected=\"selected\"" : "";
			echo "<option $selected value='". $category->term_id ."'>". $category->name ."</option>";
		}
		echo "</select>";
	}
	
	function list_images($name, $value) {
		echo "<select name=$name>";
		echo "<option value=\"\">Select Category</option>";

		$d = dir(TEMPLATEPATH . "/images");
		while (false !== ($entry = $d->read())) {
			if($entry != '.' && $entry != '..'){
				$selected = ($value == $entry) ? "selected=\"selected\"" : "";
				echo "<option $selected value='". $entry ."'>". $entry ."</option>";
			}
		}
		$d->close();
		echo "</select>";
	}



	function wp_settings_html(){
	include (TEMPLATEPATH . '/wpress_defaults.php');
?>
<div class="wrap">
	<div id="icon-options-general" class="icon32"><br /></div>
	<h2>WPress General Settings</h2>
	
	
	<form method="post" action="options.php">
	<?php settings_fields('wpress-settings'); ?>
	<table class="form-table">

	<tr valign="top">
	<th scope="row">
		<label for="blogname">Site Logo</label>
	</th>
	<td>
	<?php

		$sitelogo =  get_option('sitelogo', $wp_sitelogo);
		if($sitelogo == ""){
			$sitelogo = "logo.png";
		}
		list_images("sitelogo",$sitelogo);
	?>
	</td>
	</tr>
	
	<tr valign="top">
	<th scope="row">
		<label for="blogname">Copyright Text</label>
	</th>
	<td>
		<textarea name="copyright_text" rows="2" cols="10" class="large-text"><?php echo get_option('copyright_text', $wp_copyright_text); ?></textarea>
	</td>
	</tr>
	
	<tr valign="top">
	<th scope="row">
		<label for="blogname">Footer Social Network Icons</label>
	</th>
	<td>
		<textarea name="social_icons" rows="11" cols="50" class="large-text"><?php echo get_option('social_icons', $wp_social_networks); ?></textarea>
	</td>
	</tr>
	
	<tr valign="top">
	<th scope="row">
		<label for="blogname">Google Analytics Key</label>
	</th>
	<td>
		<input name="google_analytics_key" type="text" id="google_analytics_key" value="<?php echo get_option('google_analytics_key'); ?>" class="regular-text" />	
	</td>
	</tr>
	
	<tr valign="top">
	<th colspan="2" scope="row">
		<div id="icon-options-general" class="icon32"><br /></div>
		<h2>WPress News Ticker Settings</h2>
	</th>
	</tr>


	<tr valign="top">
	<th scope="row">
		<label for="blogname">Enable News Ticker</label>
	</th>
	<td>
		<input name="disable_newsticker" type="radio" value="0" <?php if(get_option('disable_newsticker') == 0){ echo "checked=\"checked\""; } ?>/> No, Thanks &nbsp;&nbsp; 
		<input name="disable_newsticker" type="radio" value="1" <?php if(get_option('disable_newsticker',1) == 1){ echo "checked=\"checked\""; } ?>/> Yes, please<br />
   	</td>
	</tr>
	   	
	<tr valign="top">
	<th scope="row">
		<label for="blogname">News Ticker Title</label>
	</th>
	<td>
		<input name="ticker_title" type="text" id="ticker_title" value="<?php echo get_option('ticker_title', $wp_ticker_title); ?>" class="regular-text" />	
	</td>
	</tr>
	
	<tr valign="top">
	<th scope="row">
		<label for="blogname">Choose category to join News</label>
	</th>
	<td>
	<?php
		$current_value =  get_option('ticker_category_id');
		list_categories("ticker_category_id",$current_value);
	?>
	</td>
	</tr>

	<tr valign="top">
	<th scope="row">
		<label for="blogname">How many news to show</label>
	</th>
	<td>
		<input name="ticker_limit" type="text" id="ticker_limit" value="<?php echo get_option('ticker_limit', 10); ?>" class="small-text" />
	</td>
	</tr>
	
	
	<tr valign="top">
	<th colspan="2" scope="row">
		<div id="icon-options-general" class="icon32"><br /></div>
		<h2>WPress General Words</h2>
	</th>
	</tr>
	
	<tr valign="top">
	<th scope="row">
		<label for="blogname">Pages ShortCut Name</label>
	</th>
	<td>
		<input name="short_cut" type="text" id="short_cut" value="<?php echo get_option('short_cut', $wp_short_cut); ?>" class="regular-text" />	
	</td>
	</tr>
	
	<tr valign="top">
	<th scope="row">
		<label for="blogname">News Details Name</label>
	</th>
	<td>
		<input name="news_name" type="text" id="news_name" value="<?php echo get_option('news_name', $wp_news_name); ?>" class="regular-text" />
		How many item displayed ? <input name="news_limit" type="text" id="news_limit" value="<?php echo get_option('news_limit', 10); ?>" class="small-text" />	
	</td>
	</tr>
		
	<tr valign="top">
	<th scope="row">
		<label for="blogname">Portfolio Details Name</label>
	</th>
	<td>
		<input name="portfolio_name" type="text" id="portfolio_name" value="<?php echo get_option('portfolio_name', $wp_portfolio_name); ?>" class="regular-text" />
		How many item displayed ? <input name="portfolio_limit" type="text" id="portfolio_limit" value="<?php echo get_option('portfolio_limit', 10); ?>" class="small-text" />	
	</td>
	</tr>	
	
	
	<tr valign="top">
	<th scope="row">
		<label for="blogname">&laquo; Older Entries</label>
	</th>
	<td>
		<input name="older_entries" type="text" id="older_entries" value="<?php echo get_option('older_entries', $wp_older); ?>" class="regular-text" />
	</td>
	</tr>	
	
	<tr valign="top">
	<th scope="row">
		<label for="blogname">Newer Entries &raquo;</label>
	</th>
	<td>
		<input name="newer_entries" type="text" id="newer_entries" value="<?php echo get_option('newer_entries', $wp_newer); ?>" class="regular-text" />
	</td>
	</tr>

	<tr valign="top">
	<th scope="row">
		<label for="blogname">Sub Navigation Name</label>
	</th>
	<td>
		<input name="sub_navigation" type="text" id="sub_navigation" value="<?php echo get_option('sub_navigation', $wp_sub); ?>" class="regular-text" />
	</td>
	</tr>	
	
	<tr valign="top">
	<th scope="row">
		<label for="blogname">Page Back Name</label>
	</th>
	<td>
		<input name="back_name" type="text" id="back_name" value="<?php echo get_option('back_name', $wp_back_name); ?>" class="regular-text" />
	</td>
	</tr>
	
	
	<tr valign="top">
	<th scope="row">
		<label for="blogname">Search Name</label>
	</th>
	<td>
		<input name="search_name" type="text" id="search_name" value="<?php echo get_option('search_name', $wp_search_name); ?>" class="regular-text" />
	</td>
	</tr>
	
	
	<tr valign="top">
	<th scope="row">
		<label for="blogname">Search Result Name</label>
	</th>
	<td>
		<input name="result_name" type="text" id="result_name" value="<?php echo get_option('result_name', $wp_result_name); ?>" class="regular-text" />
	</td>
	</tr>
		
	<tr valign="top">
	<th scope="row">
	    <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
	</th>
	</tr>
	
	</table>

	</form>
</div>
<?php 
	} 
	
	function wp_widget_settings_html(){
	include (TEMPLATEPATH . '/wpress_defaults.php');
?>
<div class="wrap">
	<div id="icon-options-general" class="icon32"><br /></div>
	<h2>WPress Custom Widgets Settings</h2>
	
	
	<form method="post" action="options.php">
	<?php settings_fields('wpress-widgets'); ?>
	<table class="form-table">
	
	<tr valign="top">
	<th scope="row">
		<label for="blogname">Footer Column <strong>#1</strong></label>
	</th>
	<td>
		<textarea name="footer_column_1" rows="11" cols="50" class="large-text"><?php echo get_option('footer_column_1', $wp_footer_column_1); ?></textarea>
	</td>
	</tr>
	
	<tr valign="top">
	<th scope="row">
		<label for="blogname">Footer Column <strong>#2</strong></label>
	</th>
	<td>
		<textarea name="footer_column_2" rows="11" cols="50" class="large-text"><?php echo get_option('footer_column_2', $wp_footer_column_2); ?></textarea>
	</td>
	</tr>
	
	<tr valign="top">
	<th scope="row">
		<label for="blogname">Footer Column <strong>#3</strong></label>
	</th>
	<td>
		<textarea name="footer_column_3" rows="11" cols="50" class="large-text"><?php echo get_option('footer_column_3', $wp_footer_column_3); ?></textarea>
	</td>
	</tr>
	
	<tr valign="top">
	<th scope="row">
		<label for="blogname">Footer Column <strong>#4</strong></label>
	</th>
	<td>
		<textarea name="footer_column_4" rows="5" cols="50" class="large-text"><?php echo get_option('footer_column_4', $wp_footer_column_4); ?></textarea>
	</td>
	</tr>
	
	<tr valign="top">
	<th scope="row">
		<label for="blogname">Footer Column <strong>#5</strong></label>
	</th>
	<td>
		<textarea name="footer_column_5" rows="5" cols="50" class="large-text"><?php echo get_option('footer_column_5', $wp_footer_column_5); ?></textarea>
	</td>
	</tr>
	
	<tr valign="top">
	<th scope="row">
		<label for="blogname">Footer Column <strong>#6</strong></label>
	</th>
	<td>
		<textarea name="footer_column_6" rows="5" cols="50" class="large-text"><?php echo get_option('footer_column_6', $wp_footer_column_6); ?></textarea>
	</td>
	</tr>
	
	<tr valign="top">
	<th scope="row">
	    <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
	</th>
	</tr>
	
	</table>

	</form>
</div>
<?php 
	} 
	function wp_contact_html(){
	include (TEMPLATEPATH . '/wpress_defaults.php');
?>
<div class="wrap">
	<div id="icon-options-general" class="icon32"><br /></div>
	<h2>WPress Contact Settings</h2>
	
	
	<form method="post" action="options.php">
	<?php settings_fields('wpress-contact'); ?>
	<table class="form-table">
	
	<tr valign="top">
	<th scope="row">
		<label for="blogname">Location</label>
	</th>
	<td>
		<textarea name="location" rows="6" cols="50" class="large-text"><?php echo get_option('location', $wp_location); ?></textarea>
	</td>
	</tr>
	
	<tr valign="top">
	<th scope="row">
		<label for="blogname">Header</label>
	</th>
	<td>
		<textarea name="header" rows="6" cols="50" class="large-text"><?php echo get_option('header', $wp_header); ?></textarea>
	</td>
	</tr>
	
	<tr valign="top">
	<th scope="row">
		<label for="blogname">Information</label>
	</th>
	<td>
		<textarea name="information" rows="6" cols="50" class="large-text"><?php echo get_option('information', $wp_information); ?></textarea>
	</td>
	</tr>
	
	<tr valign="top">
	<th scope="row">
		<label for="blogname">E-Mail</label>
	</th>
	<td>
		<input name="email" type="text" id="email" value="<?php echo get_option('email'); ?>" class="regular-text" /> <i>default email is <strong><?php bloginfo('admin_email'); ?></strong></i>
	</td>
	</tr>
	
	<tr valign="top">
	<th colspan="2" scope="row">
		<div id="icon-options-general" class="icon32"><br /></div>
		<h2>Contact Form Titles</h2>
	</th>
	</tr>
	
	<tr valign="top">
	<th scope="row">
		<label for="blogname">Form Name</label>
	</th>
	<td>
		<input name="form_name" type="text" id="form_name" value="<?php echo get_option('form_name', $wp_form_name); ?>" class="regular-text" />
	</td>
	</tr>
	
	<tr valign="top">
	<th scope="row">
		<label for="blogname">Your Name</label>
	</th>
	<td>
		<input name="your_name" type="text" id="your_name" value="<?php echo get_option('your_name', $wp_your_name); ?>" class="regular-text" />
	</td>
	</tr>

	<tr valign="top">
	<th scope="row">
		<label for="blogname">Telephone</label>
	</th>
	<td>
		<input name="telephone" type="text" id="telephone" value="<?php echo get_option('telephone', $wp_telephone); ?>" class="regular-text" />
	</td>
	</tr>
	
	<tr valign="top">
	<th scope="row">
		<label for="blogname">E-Mail Name</label>
	</th>
	<td>
		<input name="email_name" type="text" id="email_name" value="<?php echo get_option('email_name', $wp_email_name); ?>" class="regular-text" />
	</td>
	</tr>
	
	<tr valign="top">
	<th scope="row">
		<label for="blogname">Subject</label>
	</th>
	<td>
		<input name="subject" type="text" id="subject" value="<?php echo get_option('subject', $wp_subject); ?>" class="regular-text" />
	</td>
	</tr>
	
	<tr valign="top">
	<th scope="row">
		<label for="blogname">Message</label>
	</th>
	<td>
		<input name="message" type="text" id="message" value="<?php echo get_option('message', $wp_message); ?>" class="regular-text" />
	</td>
	</tr>
	
	<tr valign="top">
	<th scope="row">
		<label for="blogname">Submit</label>
	</th>
	<td>
		<input name="submit" type="text" id="submit" value="<?php echo get_option('submit', $wp_submit); ?>" class="regular-text" />
	</td>
	</tr>
	
	<tr valign="top">
	<th scope="row">
		<label for="blogname">Reset</label>
	</th>
	<td>
		<input name="reset" type="text" id="reset" value="<?php echo get_option('reset', $wp_reset); ?>" class="regular-text" />
	</td>
	</tr>
	
	<tr valign="top">
	<th scope="row">
		<label for="blogname">Success Message</label>
	</th>
	<td>
		<input name="success" type="text" id="success" value="<?php echo get_option('success', $wp_success); ?>" class="regular-text" />
	</td>
	</tr>
	
	<tr valign="top">
	<th scope="row">
		<label for="blogname">Error Message</label>
	</th>
	<td>
		<input name="error" type="text" id="error" value="<?php echo get_option('error', $wp_error); ?>" class="regular-text" />
	</td>
	</tr>
	


	<tr valign="top">
	<th scope="row">
	    <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
	</th>
	</tr>
		
	</table>

	</form>
</div>
<?php } ?>